package com.hckjsec.oa.flow;

import com.alibaba.fastjson.JSON;
import com.hckjsec.common.utils.StringUtils;
import com.hckjsec.oa.domain.OaAuditing;

import java.util.*;

//定义审核流程
public class FlowPath {
    public static Map<String,String> typeHt=new Hashtable<String, String>();
    static {
        typeHt.put("dept_leading_official","部门审核");
        typeHt.put("human_affairs_official","人事审核");
        typeHt.put("leaders_company","公司领导审核");
        typeHt.put("finance_leading_official","财务审核");
    }
    public static String[] OA_OVERTIME = {"dept_leading_official","human_affairs_official"};// 加班申请审核  部门负责人审核-》人事负责人
    public static String[] OA_LEAVE = {"dept_leading_official","human_affairs_official"};// 请假管理审核  部门负责人审核-》人事负责人
    public static String[] OA_MISSION = {"dept_leading_official","leaders_company"};// 出差管理审核  部门负责人审核-》公司领导
    public static String[] OA_EXPENSE = {"dept_leading_official","leaders_company","finance_leading_official"};// 报销管理审核  部门负责人审核-》公司领导-》财务负责人

    //获取当前用户是否可以审批
    public static boolean isAuditing(List<String> userPostList,String type,String state){
        if (StringUtils.isEmpty(userPostList)){
            return false;
        }
        boolean flag = false;
        if ("overtime".equals(type)){
            String flow = "";
            if ("".equals(state)){
                flow = OA_OVERTIME[0];
                if (userPostList.contains(flow)){
                    flag =  true;
                }
            }else{
                int index = Arrays.binarySearch(OA_OVERTIME, state);
                if ((OA_OVERTIME.length - 1) == index){//最后一个流程
                    flag = false;
                }else{
                    flow = OA_OVERTIME[index + 1];
                    if (userPostList.contains(flow)){
                        flag =  true;
                    }
                }
            }
        }else if ("leave".equals(type)){
            String flow = "";
            if ("".equals(state)){
                flow = OA_LEAVE[0];
                if (userPostList.contains(flow)){
                    flag =  true;
                }
            }else{
                int index = Arrays.binarySearch(OA_LEAVE, state);
                if ((OA_LEAVE.length - 1) == index){//最后一个流程
                    flag = false;
                }else{
                    flow = OA_LEAVE[index + 1];
                    if (userPostList.contains(flow)){
                        flag =  true;
                    }
                }
            }
        }else if ("mission".equals(type)){
            String flow = "";
            if ("".equals(state)){
                flow = OA_MISSION[0];
                if (userPostList.contains(flow)){
                    flag =  true;
                }
            }else{
                int index = Arrays.binarySearch(OA_MISSION, state);
                if ((OA_MISSION.length - 1) == index){//最后一个流程
                    flag = false;
                }else{
                    flow = OA_MISSION[index + 1];
                    if (userPostList.contains(flow)){
                        flag =  true;
                    }
                }
            }
        }else if ("expense".equals(type)){
            String flow = "";
            if ("".equals(state)){
                flow = OA_EXPENSE[0];
                if (userPostList.contains(flow)){
                    flag =  true;
                }
            }else{
                int index = Arrays.binarySearch(OA_EXPENSE, state);
                if ((OA_EXPENSE.length - 1) == index){//最后一个流程
                    flag = false;
                }else{
                    flow = OA_EXPENSE[index + 1];
                    if (userPostList.contains(flow)){
                        flag =  true;
                    }
                }
            }
        }
        return flag;
    }



    public static void main(String[] args) {
        List<OaAuditing> auditingList = new ArrayList<>();
    }
}
